<template>
	<view class="container contes">
		<view class="head-title relative">
			登录
			<view class="absolute left-[20rpx] top-[95rpx]" @click="gotoindex">
					<u-icon name="home" color="#999" size="24"></u-icon>
			</view>
		</view>
		<view class="logoimg">
			<view class="">
				<image :src="store.logotype==1?'../../static/homeimg/login.png':'../../static/homeimg/logotwo.jpg'" class="img" mode="aspectFit"></image>
			</view>
		</view>
		<view class="title">
			{{store.logotype==1?'点老板':'咚点西点'}}
		</view>
		<button v-if="radiovalue.list.length<1" class="onejianlogin" @click="getPhoneNumber"
			boder="none">手机号一键登录</button>
		<button v-else class="onejianlogin" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
			boder="none">手机号一键登录</button>
		<button class="onejianlogins mt20" type="default" boder="none" @click="navto">手机号登录注册</button>
	<!-- 	<view class="ischeckbox">
			<view class="flex flex-wrap">
				<view class="center">
					<uv-checkbox-group labelColor="#B7B7B7" v-model="radiovalue.list" @change="agreetext" :size="13"
						shape="circle">
						<uv-checkbox shape="circle" top="50"  :name="1">
						</uv-checkbox>
					</uv-checkbox-group>
				</view>
					<text class="textagree">我已阅读并同意</text>
				<template v-for="(item, index) in userw.list">
					<text class="center text-[24rpx] leading-[24rpx] text-[#FE861C]"  @click="toAgreements(item,index)">
						《{{item.name}}》
					</text>
				</template>
			</view>
		</view> -->
		<view class="text-[#000000] ischeckbox text-[12px]  px-[35rpx]">
			<view class="radio flex items-center">
				<view class="px-[20rpx] pr-0 h-full relative flex items-start top-[12rpx]" @click="choseagree">
					<uv-checkbox-group labelColor="#B7B7B7" active-color="#FE861C" v-model="radiovalue.list"
						@change="agreetext" :size="13" shape="circle">
						<uv-checkbox shape="circle" top="50" :name="1">
						</uv-checkbox>
					</uv-checkbox-group>
				</view>
				<view class="">
					<text>我已阅读并同意</text>
					<template v-for="(item, index) in userw.list">
						<text @click="toAgreements(item,index)"
							class="text-[#FE861C]">《{{item.name}}》</text>
					</template>
		
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		onBackPress(options) {
			console.log('from:' + options.from)
		}
	}
</script>
<script setup>
	import {
		useStore
	} from '@/stores/user.js'
	const store = useStore();
	import {
		loginin,
		agreements
	} from '@/api/home.js'
	import {
		ref,
		reactive
	} from "vue"
	import {
		onShow
	} from "@dcloudio/uni-app"
	let userw = reactive({
		list: []
	})
	const gotoindex=()=>{
		uni.switchTab({
			url:"/pages/index/index"
		})
	}
	onShow(() => {
		agreements().then(res => {
			userw.list = res.result
			console.log(res, "111111")
		})
	})
	//获取协议
	const toAgreements = (item, index) => {
		uni.navigateTo({
			url: `/pages/login/userAgreement?index=${item.id}`
		});
	}
	const radiovalue = reactive({
		list: []
	})
	const choseagree = () => {
		if (radiovalue.list.length > 0) {
				radiovalue.list = []
		} else {
			radiovalue.list = [1]
		}
	}
	const agreetext = (e) => {
		console.log(e, "111", radiovalue.list)
	}
	const navto = () => {
		switch (true) {
			case radiovalue.list.length < 1:
				uni.showToast({
					title: "请先同意协议",
					icon: "none"
				})
				return;
		}
		uni.navigateTo({
			url: "/pages/phonelogin/phonelogin"
		})
	}
	const getPhoneNumber = (res) => { // 获取手机号
		switch (true) {
			case radiovalue.list.length < 1:
				uni.showToast({
					title: "请先同意协议",
					icon: "none"
				})
				return;
		}
		if (res.detail.code) {
			uni.login({
				"provider": "weixin",
				"onlyAuthorize": true, // 微信登录仅请求授权认证
				success: function(event) {
					const {
						code
					} = event
					loginin({
						phone: "13881574738",
						code: code,
						telCode: "",
						wtelCode: res.detail.code,
						loginType: 1,
						isAgreement: true
					}).then(res => {
						console.log(res)
						if (res.code == 200) {
							uni.showToast({
								icon: "none",
								title: res.msg
							})
							// uni.setStorage({
							// 	key:"loginTokenKey",
							// 	data:res.result.accessToken
							// })
							uni.setStorageSync('loginTokenKey', res.result.accessToken)
							uni.switchTab({
								url: "/pages/index/index"
							})
						} else {
							uni.showToast({
								icon: "none",
								title: res.msg
							})
						}
					})
				},
				fail: function(err) {
					// 登录授权失败  
					// err.code是错误码
				}
			})
		}

	}
</script>

<style scoped lang="scss">
	.center { 
		display: flex;
		align-items: center;
	}

	.head-title {
		text-align: center;
		padding-top: 100rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #0A0A0A;
	}

	.title {
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #000000;
		text-align: center;
		padding-bottom: 180rpx;
	}

	.container {
		height: 100vh;
		font-size: 14px;
		line-height: 24px;
	}

	.onejianlogin {
		width: 566rpx;
		height: 98rpx;
		background: #FE861C;
		line-height: 98rpx;
		color: #fff;
		border-radius: 20rpx;
		text-align: center;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}
	::v-deep(.onejianlogin::after){
		border: 0px solid #fff;
	}

	.onejianlogins {
		width: 566rpx;
		height: 98rpx;
		line-height: 98rpx;
		color: #fff;
		border-radius: 20rpx;
		text-align: center;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FE861C;
		border: 1px solid #FE861C;
	}

	.logoimg {
		width: 100%;
		display: flex;
		justify-content: center;
		padding-top: 180rpx;

		.img {
			width: 144rpx;
			height: 144rpx;
			border-radius: 20rpx;
			
		}
	}

	.ischeckbox {
		width: 100%;
		padding:0 108rpx;
		margin-top: 20rpx;
		display: flex;
		flex-wrap: wrap;

		.textagree {
			font-size: 24rpx;
			line-height: 32rpx;
			color: #B7B7B7;
		}
	}

	.mt20 {
		margin-top: 40rpx;
	}

	.contes {
		height: calc(100vh - 100rpx);
		background: url('@/static/homeimg/bgc.png') no-repeat;
		background-size: 100% 100%;
	}
</style>